findUser()ꞌ)   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 9.6666
1
/**
2
 * hsBot: Supply template and your bot is ready.
3
 * 
4
 * Hardik Shah <[email protected]>
5
 * 
6
 * MIT License
7
 */
8
9
var should = require('chai').should();
10
var expect = require('chai').expect;
11
var UserDB = require('../db/userdb');
12
13
describe('UserDB', function() {
14
15
  describe('constructor', function() {
16
    it('Array should be blank: ', function() {
17
      var userDb = new UserDB();
18
      expect(userDb.mem).to.have.length(0);
19
    });
20
  });
21
22
  describe('._insertUser()', function() {
23
    it('Should insert user.', function() {
24
      var userDb = new UserDB();
25
      userDb._insertUser("aQ11zyTr4u7I", "Hardik Shah", "Hardik Shah", "What is your name?", "call1");
26
      expect(userDb.mem).to.have.length(1);
27
    });
28
  });
29
30
  describe('._updateUser()', function() {
31
    it('Should update user.', function() {
32
      var userDb = new UserDB();
33
      userDb._insertUser("aQ11zyTr4u7I", "Hardik Shah", "Hardik Shah", "What is your name?", "call1");
34
      userDb._updateUser("aQ11zyTr4u7I", "Hardik Shah", "@hs", "What is your name?", "command");
35
      var user = userDb._findUser("aQ11zyTr4u7I");
36
      user.activities[0].pattern.should.eql("Hardik Shah");
37
      user.activities[0].topic.should.eql("call1");
38
      user.activities[1].pattern.should.eql("@hs");
39
      user.activities[1].topic.should.eql("command");
40
      user.userId.should.eql("aQ11zyTr4u7I");
41
      expect(userDb.mem).to.have.length(1);
42
      
43
    });
44
45
    it('Should not return anything if user not exists.', function() {
46
      var userDb = new UserDB();
47
      var updatedUser = userDb._updateUser("aQ11zyTr4u44", "Hardik Shah", "@hs", "What is your name?", "command");
48
      should.not.exist(updatedUser);
49
      
50
    });
51
  });
52
53
  describe('._findUser()', function() {
54
    it('Should find user.', function() {
55
      var userDb = new UserDB();
56
      userDb._insertUser("aQ11zyTr4u7I", "Hardik Shah", "Hardik Shah", "What is your name?", "call1");
57
      var user = userDb._findUser("aQ11zyTr4u7I");
58
      user.userId.should.eql("aQ11zyTr4u7I");
59
      expect(userDb.mem).to.have.length(1);
60
    });
61
  });
62
});